package com.kust.smarthome.web.controller;


import com.kust.smarthome.web.model.User;
import com.kust.smarthome.web.service.IRateService;
import com.kust.smarthome.web.service.IUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.security.Principal;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author iAuzre
 * @since 2021-07-06
 */
@RestController
@RequestMapping("/rate")
@Api(value = "心率信息相关操作", tags = {"user-tag"})
public class RateController {

    @Resource
    private IRateService rateService;

    @Resource
    private IUserService userService;

    /**
     * 通过personId获取对应的心率信息
     * @param principal Security自带
     * @param personId 由前端提供
     * @return 返回一个String数组(其中信息为每十分钟获取的一次心率信息)
     */
    @GetMapping("/getRateByPersonId")
    @ApiOperation(value = "获取关系人心率", notes = "用户通过personId(关系人id),获取关系人的心率统计")
    public String[] getRate(Principal principal, Integer personId) {
        User user = userService.getByUsername(principal.getName());
        return rateService.getRateString(user.getId(), personId);
    }
}
